package vip.xiaonuo.invoice.modular.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import vip.xiaonuo.common.annotation.CommonLog;
import vip.xiaonuo.common.pojo.CommonResult;
import vip.xiaonuo.invoice.modular.param.*;
import vip.xiaonuo.invoice.modular.service.impl.InvoiceServiceImpl;
import vip.xiaonuo.invoice.modular.vo.*;
import vip.xiaonuo.invoice.modular.service.InvoiceService;

import javax.validation.Valid;


/**
 * 发票控制器
 *
 * @author AI Assistant
 */
@Tag(name = "发票控制器")
@ApiSupport(author = "AI Assistant", order = 1)
@RestController
@Validated
public class InvoiceController {

    @Resource
    private InvoiceService invoiceService;
    @Resource
    private InvoiceServiceImpl  invoiceServiceImpl;

    /**
     * 开具电子发票
     */
    @ApiOperationSupport(order = 1)
    @Operation(summary = "开具电子发票")
    @CommonLog("开具电子发票")
    @PostMapping("/invoice/create")
    public InvoiceSubmitResultVo createInvoice(@RequestBody @Valid InvoiceRequestParam param) {
        InvoiceSubmitResultVo result = invoiceService.createInvoice(param);
        return result;
    }

    /**
     * 重新开具电子发票
     */
    @ApiOperationSupport(order = 1)
    @Operation(summary = "重新开具电子发票")
    @CommonLog("重新开具电子发票")
    @PostMapping("/invoice/reCreate")
    public InvoiceSubmitResultVo reCreateInvoice(@RequestBody @Valid ReInvoiceRequestParam reInvoiceRequestParam) {
        InvoiceSubmitResultVo result = invoiceService.reCreateInvoice(reInvoiceRequestParam);
        return result;
    }

    /**
     * 发票结果查询
     */
    @ApiOperationSupport(order = 3)
    @Operation(summary = "发票结果查询")
    @CommonLog("发票结果查询(定时任务快捷接口)")
    @PostMapping("/invoice/query")
    public CommonResult<String> queryInvoice() {
        invoiceServiceImpl.queryAndUpdateInvoice();
        return CommonResult.ok();
    }

    /**
     * 重新交付电子发票
     */
    @ApiOperationSupport(order = 3)
    @Operation(summary = "重新交付电子发票")
    @CommonLog("重新交付电子发票")
    @PostMapping("/invoice/redeliver")
    public RedeliverSubmitResultVo reDeliverInvoice(@RequestBody RedeliverRequestParam redeliverRequestParam) {
        RedeliverSubmitResultVo redeliverSubmitResultVo = invoiceService.reDeliverInvoice(redeliverRequestParam);
        return redeliverSubmitResultVo;
    }

    /**
     * 冲红发票
     */
    @ApiOperationSupport(order = 4)
    @Operation(summary = "冲红发票")
    @CommonLog("冲红发票")
    @PostMapping("/invoice/red")
    public RedInvoiceSubmitResultVo redInvoice(@RequestBody RedInvoiceRequestParam redInvoiceRequestParam) {
        RedInvoiceSubmitResultVo redInvoiceSubmitResultVo = invoiceService.createRedInvoice(redInvoiceRequestParam);
        return redInvoiceSubmitResultVo;
    }


    /**
     * 红票结果查询
     */
    @ApiOperationSupport(order = 5)
    @Operation(summary = "红票结果查询")
    @CommonLog("红票结果查询(定时任务快捷接口)")
    @PostMapping("/invoice/red/query")
    public CommonResult<String> queryRedInvoice() {
        invoiceServiceImpl.queryAndUpdateRedInvoice();
        return CommonResult.ok();
    }

    @ApiOperationSupport(order = 4)
    @Operation(summary = "获取手机号验证码")
    @CommonLog("获取手机号验证码")
    @PostMapping("/invoice/validCode/get")
    public GetValidSubmitResultVo getValidCode(@RequestBody GetValidCodeRequestParam getValidCodeRequestParam) {
        GetValidSubmitResultVo result = invoiceService.getValidCode(getValidCodeRequestParam);
        return result;
    }


    @ApiOperationSupport(order = 4)
    @Operation(summary = "提交手机号验证码")
    @CommonLog("提交手机号验证码")
    @PostMapping("/invoice/validCode/commit")
    public CommitValidSubmitResultVo commitValidCode(@RequestBody CommitValidCodeRequestParam commitValidCodeRequestParam) {
        CommitValidSubmitResultVo result = invoiceService.commitValidCode(commitValidCodeRequestParam);
        return result;
    }

}
